#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<functional>
#include<queue>
#include<stack>
#include<list>
using namespace std;

int main(){
    // vector<int> prices =  {7,1,5,3,6,4};
    vector<int> prices ={1,2,3,4,5};
    int n_size = prices.size();
    for(int i =0;i<n_size;++i){
        cout<<prices[i]<<" ";
    }
    int stock_now = 0, sum = 0;
    // int sum=0;
    cout<<endl;
    vector<vector <int>> stock(n_size,vector<int>(2));
    for (int i =0 ;i<stock.size();++i){
        for(int j=0;j<stock[0].size();++j){
            cout<<stock[i][j]<<" ";
        }
        cout<<endl;
    }
    stock[0][0]=0;//没有
    stock[0][1]=-prices[0];//持有
    //想尝试一下DP，该如何操作呢
    for (int i =1;i<n_size;++i){
        //转移方程
        //第i天没有，则第i天卖了，或者i-1天也是没有
        //第i天持有，则第i天买了，或者i-1天也有
        stock[i][0]=max(stock[i-1][0],stock[i-1][1]+prices[i]);
        cout<< "i="<<i<<":"<<stock[i][0]<<endl;
        stock[i][1]=max(stock[i-1][1],stock[i-1][0]-prices[i]);
        cout<< "i="<<i<<":"<<stock[i][1]<<endl;
    }

    for(int i =0 ; i<n_size-1;++i){
        if(prices[i]<prices[i+1]){
            sum+=prices[i+1]-prices[i];
        }
    }
    cout<<"stock[n_size-1][0] max profit is:"<<stock[n_size-1][0]<<endl;
    cout<<"sum   max profit is:"<<sum<<endl;
    printf("love han");
    system("pause");
    return 0;
}